package com.forekenow.work0723;

public class Student {
    private int grade;
    private String name;
    private int sno;


    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSno() {
        return sno;
    }

    public void setSno(int sno) {
        this.sno = sno;
    }

    public static void sort(Student[] aa) {
        for (int i=0;i<2;i++){
            for(int j =0;j<2-i;j++){
                if (aa[j].grade<aa[j+1].grade){
                    Student temp = aa[j];
                    aa[j]=aa[j+1];
                    aa[j+1]=temp;
                }
            }
        }
    }
    public void show(Student[] array){
        for (Student aa:array) {
            System.out.println(aa.getSno() + "" + aa.getName() + "" + aa.getGrade());
        }
    }

    public static void main(String[] args) {
        Student[] array = new Student[3];
        Student s1 = new Student();
        s1.setName("tom");
        s1.setGrade(23);
        s1.setSno(2);
        Student s2 = new Student();
        s2.setName("jack");
        s2.setGrade(25);
        s2.setSno(1);
        Student s3 = new Student();
        s3.setName("ros");
        s3.setGrade(18);
        s3.setSno(3);
        //3.将对象保存到数组中
        array[0] = s1;
        array[1] = s2;
        array[2] = s3;
        Student student = new Student();
        student.sort(array);
        student.show(array);
    }
}